package com.example.baiduapi.serviceListener.old.service;

import com.alibaba.fastjson.JSONObject;
import com.example.baiduapi.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


@Service("oldMvcController")
public class OldMvcService {

    private final List<String> customTables = Arrays.asList("MvcService1", "MvcService2", "MvcService3"); // 版本选择器

    @Autowired
    private List<MvcService> handlers;
    public AjaxResult versionSelector(String versionBeanName, JSONObject params){
        String beanName = getNameOrDefault(versionBeanName);
        for (MvcService bean : handlers) {
            if (bean.getName().equals(beanName)) {
                return bean.mvcFunction(params);
            }
        }
        return AjaxResult.error("未找到对应服务");
    }


    private String getNameOrDefault(String name) {
        return customTables.contains(name) ? name : "new";
    }
}
